import request from './request';

// 获取当天的基础信息
export const getTodayBasicInfo = () => {
  return request.get('/basic-info/today');
};

// 根据评测日期获取基础信息列表
export const getBasicInfoByDate = (评测日期) => {
  return request.get(`/basic-info/${encodeURIComponent(评测日期)}`);
};

// 根据评测日期获取牌别选项
export const getBrandsByDate = (评测日期) => {
  return request.get(`/basic-info/${encodeURIComponent(评测日期)}/brands`);
};

// 根据评测日期和牌别获取批次选项
export const getBatchesByDateAndBrand = (评测日期, 牌别) => {
  return request.get(`/basic-info/${encodeURIComponent(评测日期)}/${encodeURIComponent(牌别)}/batches`);
};

// 根据评测日期、牌别、批次获取日期选项
export const getDatesByDateBrandAndBatch = (评测日期, 牌别, 批次) => {
  return request.get(`/basic-info/${encodeURIComponent(评测日期)}/${encodeURIComponent(牌别)}/${encodeURIComponent(批次)}/dates`);
};

// 创建基础信息
export const createBasicInfo = (data) => {
  return request.post('/basic-info', data);
};

// 获取当天的评价信息
export const getTodayEvaluation = () => {
  return request.get('/evaluation/today');
};

// 根据评测日期获取评价信息
export const getEvaluationByDate = (评测日期, 牌别 = null, 批次 = null) => {
  let url = `/evaluation/${encodeURIComponent(评测日期)}`;
  const params = [];
  if (牌别 && 批次) {
    params.push(`牌别=${encodeURIComponent(牌别)}`, `批次=${encodeURIComponent(批次)}`);
  }
  if (params.length > 0) {
    url += '?' + params.join('&');
  }
  return request.get(url);
};

// 更新评价表
export const updateEvaluation = (data) => {
  return request.put('/evaluation', data);
};

// 获取当天的缺陷描述
export const getTodayDefect = () => {
  return request.get('/defect/today');
};

// 根据评测日期获取缺陷描述
export const getDefectByDate = (评测日期) => {
  return request.get(`/defect/${encodeURIComponent(评测日期)}`);
};

// 创建或更新缺陷描述
export const saveDefect = (data) => {
  return request.post('/defect', data);
};

